import collections


class Solution(object):
    def longestArithSeqLength(self, nums):
        n = len(nums)
        DP = [collections.defaultdict(int) for _ in range(n)]
        max_len = 2
        DP[1][nums[1] - nums[0]] = 1
        for i in range(2, n):
            for j in range(i):
                DP[i][nums[i] - nums[j]] = DP[j][nums[i] - nums[j]] + 1
                max_len = max(max_len, DP[i][nums[i] - nums[j]] + 1)
        return max_len


data = Solution()
nums = [9, 4, 7, 2, 10]
print(data.longestArithSeqLength(nums))
